package com.nbsystem.controller;

import com.nbsystem.entity.ElcInfotype;
import com.nbsystem.entity.ElcUserInfotype;
import com.nbsystem.entity.SysUser;
import com.nbsystem.service.ElcUserInfotypeService;
import com.nbsystem.util.Const;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * (ElcUserInfotype)表控制层
 *
 * @author makejava
 * @since 2021-06-02 19:55:59
 */
@RestController
@RequestMapping("elcUser")
public class ElcUserInfotypeController {
    /**
     * 服务对象
     */
    @Resource
    private ElcUserInfotypeService elcUserInfotypeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ElcUserInfotype selectOne(Integer id) {
        return this.elcUserInfotypeService.queryById(id);
    }

    @RequestMapping("queryAll")
    public List<ElcUserInfotype> queryAll(Integer userId){
        ElcUserInfotype elcUserInfotype = new ElcUserInfotype();
        elcUserInfotype.setUserId(userId);
        return this.elcUserInfotypeService.queryAll(elcUserInfotype);
    }

    @RequestMapping("deleteInfoType/{id}")
    public String delete(@PathVariable Integer id){
        elcUserInfotypeService.deleteById(id);
        return "success";
    }


    @RequestMapping("queryAllByUserId")
    public List<ElcUserInfotype> queryAllByUserId(HttpServletRequest request){
        HttpSession session = request.getSession();
        SysUser sysUser = (SysUser) session.getAttribute(Const.USERSESSION);
        ElcUserInfotype elcUserInfotype = new ElcUserInfotype();
        elcUserInfotype.setUserId(sysUser.getId());
        return this.elcUserInfotypeService.queryAll(elcUserInfotype);
    }



}
